package org.ngbx.demo.flink.clickevent.statistics.event;

import org.apache.flink.api.common.serialization.DeserializationSchema;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
import org.ngbx.demo.flink.clickevent.UserClickedEvent;

import java.io.IOException;

public class UserClickedEventDeserializationSchema implements DeserializationSchema<UserClickedEvent> {
    // 注册JavaTimeModule，支持LocalDateTime字段的解析
    final private ObjectMapper objectMapper = new ObjectMapper();

    @Override
    public UserClickedEvent deserialize(byte[] message) throws IOException {
        return objectMapper.readValue(message, UserClickedEvent.class);
    }

    @Override
    public boolean isEndOfStream(UserClickedEvent nextElement) {
        return false;
    }

    @Override
    public TypeInformation<UserClickedEvent> getProducedType() {
        return TypeInformation.of(UserClickedEvent.class);
    }
}
